import { Button, message } from 'antd'
import React from 'react'
import style from './index.module.css'
import { post } from '../../util/post'
import { useNavigate } from 'react-router-dom'
export default function Beshop() {
  const token = localStorage.getItem('TOKEN')
  const navigate = useNavigate()
  const handleApply = async () => {
    const res = await post('/user/userrole/beShop',{},token)
    const {code,msg} = res.data
    if(code===0)
    {
      message.success(msg,'需要重新登录哦~')
      post('/auth/logout').then(res=>{
        if(res.data.code===0)
        {
            navigate('/login',{replace:true})
            localStorage.removeItem('TOKEN')
            localStorage.removeItem('roles')
        }
        else
          message.error(res.data.errorMsg)
      })
    }
    else message.error(msg)
  }
  return (
    <div className={style.bg}>
      <div className={style.tips}>
        <span>
          我想成为商家
        </span>
        <span>
          <Button type='primary' onClick={() => {handleApply()}}>申请成为商家</Button>
        </span>
      </div>
    </div>
  )
}
